@categories = {
  'opensuse-leap': %w{Oss Non-Oss Update-Oss Update-Non-Oss},
  'opensuse-tumbleweed': %w{Oss Non-Oss}
}
@vendors = {
  'system': {
    name: 'openSUSE',
    note: '为系统自带的软件源'
  },
  'aliyun': {
    name: 'Aliyun',
    host: 'https://mirrors.aliyun.com/opensuse'
  },
  'ustc': {
    name: 'USTC',
    host: 'https://mirrors.ustc.edu.cn/opensuse'
  }
}

def find_opensuse_version(mode = 'simple')
  release_info = File.read('/etc/os-release')
  release_hash = release_info.split("\n").reject do |line|
    line.start_with?('#')
  end.map do |line|
    name, value = line.split('=')
    value = value[1..-2] if value.start_with?('"') && value.end_with?('"')
    [name, value]
  end.to_h
  mode == 'simple' ? release_hash['VERSION_ID'] : [release_hash['ID'], release_hash['VERSION_ID']]
end

def normalize_repo_name(vendor, version, category)
  if version[0] == 'opensuse-leap'
    "#{vendor}-#{version[1]}-#{category}"
  elsif version[0] == 'opensuse-tumbleweed'
    "#{vendor}-Tumbleweed-#{category}"
  else
    "#{vendor}-#{version.join('-')}-#{category}"
  end
end

def vendors_help()
  @vendors.map do |key, config|
    "- #{key}#{config.key?(:note) ? ': ' + config[:note] : ''}"
  end.join("\n")
end

